//
//  DiscoverViewController.m
//  Anyair
//
//  Created by karlcool on 14-5-14.
//  Copyright (c) 2014年 Karlcool. All rights reserved.
//

#import "DiscoverViewController.h"
#import "DiscoverCell.h"

@interface DiscoverViewController ()

@end

@implementation DiscoverViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    disTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height-110) style:UITableViewStylePlain];
    disTableView.dataSource = self;
    disTableView.delegate = self;
    disTableView.rowHeight = 120;
    [self.view addSubview:disTableView];
    if (IOS_7) {
        disTableView.separatorInset = UIEdgeInsetsZero;
    }
    //假数据
    DisModel *dis = [[DisModel alloc]init];
    dis.disContent = @"文章简介文章简介文章简介文章简介文章简介文章简介";
    dis.disDate = @"2014-5-22 21:56";
    dis.disTitle = @"文章标题";
    
    dataArray = [@[dis,dis,dis,dis,dis] mutableCopy];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    DiscoverCell *cell = (DiscoverCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DiscoverCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
        
    }
    
    DisModel *tempModel = dataArray[indexPath.row];
    cell.disText.text = tempModel.disContent;
    cell.disTitle.text = tempModel.disTitle;
    cell.disTime.text = tempModel.disDate;
    [cell.disImage setImageWithURL:[NSURL URLWithString:tempModel.disImageUrl] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
        ;
    }];
    
    
    return cell;
}

@end
